﻿using Common.Infrastructure;
using Microsoft.AspNetCore.Mvc;
using Report.Api.Models;
using Report.Api.Models.Tier;
using StatsData.Api.Models;
using StatsData.Api.Service;
using StatsData.Data.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Common.AspNetCore.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class SyncController : ApiControllerBase
    {
        private readonly SyncService syncService;

        public SyncController(IServiceProvider provider, SyncService syncService)
             : base(provider)
        {
            this.syncService = syncService;
        }

        /// <summary>
        /// 同步组织
        /// </summary>
        /// <returns></returns>
        [HttpPost, Route("SyncOrg")]
        public async Task<ApiActionResult<bool>> SyncOrg()
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncOrgAsync();
            });
        }

        /// <summary>
        /// 同步部门
        /// </summary>
        /// <param name="apiParam"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncDepartment")]
        public async Task<ApiActionResult<bool>> SyncDepartment(ApiParam apiParam)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncDepartmentAsync(apiParam);
            });
        }

        /// <summary>
        /// 同步人员
        /// </summary>
        /// <param name="apiParam"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncUser")]
        public async Task<ApiActionResult<bool>> SyncUser(ApiParam apiParam)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncUserAsync(apiParam);
            });
        }

        /// <summary>
        /// 同步产线
        /// </summary>
        /// <param name="apiParam"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncLine")]
        public async Task<ApiActionResult<bool>> SyncLine(List<Line> apiParam)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncLineAsync(apiParam);
            });
        }

        /// <summary>
        /// 同步不良
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncBad")]
        public async Task<ApiActionResult<bool>> SyncBad(List<BadRecordModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncBadAsync(model);
            });
        }

        /// <summary>
        /// 同步OQC
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncOQC")]
        public async Task<ApiActionResult<bool>> SyncOQC(List<OQCStatisModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncOQCAsync(model);
            });
        }

        /// <summary>
        /// 同步异常
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncException")]
        public async Task<ApiActionResult<bool>> SyncException(List<QCExceptionModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncExceptionAsync(model);
            });
        }

        /// <summary>
        /// 同步CSI
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncCSI")]
        public async Task<ApiActionResult<bool>> SyncCSI(CSIModel model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncCSIAsync(model);
            });
        }

        /// <summary>
        /// 同步生产数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncProduce")]
        public async Task<ApiActionResult<bool>> SyncProduce(List<ProduceSyncModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncProduceAsync(model);
            });
        }

        /// <summary>
        /// 同步齐套
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncOwe")]
        public async Task<ApiActionResult<bool>> SyncOwe(List<SyncWorkOweStatisModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncOweAsync(model);
            });
        }

        /// <summary>
        /// 同步验货数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncShipment")]
        public async Task<ApiActionResult<bool>> SyncShipment(List<TimeShippmentModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncShipmentAsync(model);
            });
        }

        /// <summary>
        /// 同步FPY
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncFPY")]
        public async Task<ApiActionResult<bool>> SyncFPY(List<FPYModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncFPYAsync(model);
            });
        }

        /// <summary>
        /// 同步经营目标
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncObjective")]
        public async Task<ApiActionResult<bool>> SyncObjective(List<OperatingObjectiveModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncObjectiveAsync(model);
            });
        }

        /// <summary>
        /// 同步在制工单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncWorkInProcess")]
        public async Task<ApiActionResult<bool>> SyncWorkInProcess(List<WorkInProcessModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncWorkInProcessAsync(model);
            });
        }

        /// <summary>
        /// 同步费用
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncExpense")]
        public async Task<ApiActionResult<bool>> SyncExpense(List<ExpenseModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncExpenseAsync(model);
            });
        }

        /// <summary>
        /// 同步制造率
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncManufacturingRate")]
        public async Task<ApiActionResult<bool>> SyncManufacturingRate(List<ManufacturingRate> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncManufacturingRateAsync(model);
            });
        }

        /// <summary>
        /// 同步提案
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncMotion")]
        public async Task<ApiActionResult<bool>> SyncMotion(MotionModel model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncMotionAsync(model);
            });
        }

        /// <summary>
        /// 同步超领
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncExceed")]
        public async Task<ApiActionResult<bool>> SyncExceed(ExceedModel model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncExceedAsync(model);
            });
        }

        /// <summary>
        /// 同步OEE数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncOEE")]
        public async Task<ApiActionResult<bool>> SyncOEE(List<OEEParamModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncOeeAsync(model);
            });
        }

        /// <summary>
        /// 同步OTD数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncOtdData")]
        public async Task<ApiActionResult<bool>> SyncOTD(List<ODTParamModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncOtdAsync(model);
            });
        }

        /// <summary>
        /// 层级看板 - 安全管理 - 安全录入 - 同步
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncLineSafetyData")]
        public async Task<ApiActionResult<bool>> SyncLineSafetyData(List<LineSafetySyncModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncLineSafetyAsync(model);
            });
        }

        /// <summary>
        /// 层级看板 - 问题跟踪 - 同步
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncWipIssueRecordData")]
        public async Task<ApiActionResult<bool>> SyncTierWipIssueRecordData(List<TierWipIssueRecordSyncModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncTierWipIssueRecordAsync(model);
            });
        }

        /// <summary>
        /// 层级看板 - 直接人员出勤 - 同步
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncTierDepartmentAttendanceData")]
        public async Task<ApiActionResult<bool>> SyncTierDepartmentAttendanceData(List<TierDepartmentAttendanceSyncModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncTierDepartmentAttendanceAsync(model);
            });
        }

        /// <summary>
        /// 层级看板 - 安灯数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncAndonData")]
        public async Task<ApiActionResult<bool>> SyncAndonData(List<AndonSyncModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncAndonDataAsync(model);
            });
        }

        /// <summary>
        /// 层级看板 - 出货验货
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncShipmentExamine")]
        public async Task<ApiActionResult<bool>> SyncShipmentExamine(List<SyncShipmentExamineResultModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncShipmentExamineAsync(model);
            });
        }

        /// <summary>
        /// 层级看板 - 在制工单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncInProcessWork")]
        public async Task<ApiActionResult<bool>> SyncInProcessWork(List<WorkInProcessSyncModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncInProcessWorkAsync(model);
            });
        }

        /// <summary>
        /// 层级看板 - 线体FPY
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncLineFpy")]
        public async Task<ApiActionResult<bool>> SyncLineFpy(List<SyncLineFpyModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncLineFpyAsync(model);
            });
        }

        /// <summary>
        /// 层级看板 - 线体FPY
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncKpi")]
        public async Task<ApiActionResult<bool>> SyncLineKpiStatis(List<SyncLineKpiModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncLineKpiStatisAsync(model);
            });
        }

        /// <summary>
        /// 层级看板 - 线体FPY
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncLineMotion")]
        public async Task<ApiActionResult<bool>> SyncLineMotion(List<SyncLineMotionModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncLineMotionAsync(model);
            });
        }

        /// <summary>
        /// 层级看板 - 线体FPY
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncLineFpyBase")]
        public async Task<ApiActionResult<bool>> SyncLineFpyBase(List<SyncLineFpyBaseModel> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncLineFpyBaseModelAsync(model);
            });
        }

        /// <summary>
        /// 同步工时效率
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncManuSourceHourEfficiency")]
        public async Task<ApiActionResult<bool>> SyncManuSourceHourEfficiency(List<t_manu_source_hour_efficiency> model)
        {
            return await SafeExecuteAsync<bool>(async (param) =>
            {
                return await this.syncService.SyncManuSourceHourEfficiencyAsync(model);
            });
        }

        /// <summary>
        /// 同步月规划产能
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost, Route("SyncCapacityPlan")]
        public async Task<ApiActionResult<bool>> SyncCapacityPlan(List<SyncCapacityPlanModel> model)
        {
            return await SafeExecuteAsync(async (param) =>
            {
                return await syncService.SyncCapacityPlanAsync(model);
            });
        }
    }
}
